var test = (function () {

  var test = {};

  var MAX_SEARCH_TIME = 10000; //搜索控件时超时时间 http://doc.autoxjs.com/#/widgetsBasedAutomation?id=uiselectorfindonetimeout

  function bezier_curves(cp, t) {
    cx = 3.0 * (cp[1].x - cp[0].x);
    bx = 3.0 * (cp[2].x - cp[1].x) - cx;
    ax = cp[3].x - cp[0].x - cx - bx;
    cy = 3.0 * (cp[1].y - cp[0].y);
    by = 3.0 * (cp[2].y - cp[1].y) - cy;
    ay = cp[3].y - cp[0].y - cy - by;

    tSquared = t * t;
    tCubed = tSquared * t;
    result = {
      x: 0,
      y: 0,
    };
    result.x = ax * tCubed + bx * tSquared + cx * t + cp[0].x;
    result.y = ay * tCubed + by * tSquared + cy * t + cp[0].y;
    return result;
  }

  //仿真随机带曲线滑动
  //qx, qy, zx, zy, time 代表起点x,起点y,终点x,终点y,过程耗时单位毫秒
  function sml_move(qx, qy, zx, zy, time) {
    var xxy = [time];
    var point = [];
    var dx0 = {
      x: qx,
      y: qy,
    };

    var dx1 = {
      x: random(qx - 100, qx + 100),
      y: random(qy, qy + 50),
    };
    var dx2 = {
      x: random(zx - 100, zx + 100),
      y: random(zy, zy + 50),
    };
    var dx3 = {
      x: zx,
      y: zy,
    };
    point.push(dx0);
    point.push(dx1);
    point.push(dx2);
    point.push(dx3);

    for (let i = 0; i < 1; i += 0.08) {
      xxyy = [
        parseInt(bezier_curves(point, i).x),
        parseInt(bezier_curves(point, i).y),
      ];

      xxy.push(xxyy);
    }

    gesture.apply(null, xxy);
  }
  var utils$7 = {
    click_ocr_text(ocr_text) {
      this.click_bounds(ocr_text.bounds);
    },
    click_ui_control(ui_control) {
      //点击ui控件
      while (true) {
        if (ui_control && ui_control.clickable()) {
          ui_control.click();
          return true;
        } else if (ui_control) {
          ui_control = ui_control.parent();
        } else {
          return false;
        }
      }
    },
    click_bounds(bounds) {
      return this.click_x_y(bounds.centerX(), bounds.centerY());
    },
    exists_text(content) {
      if (text(content).exists()) {
        return text(content).findOne(MAX_SEARCH_TIME);
      } else {
        return false;
      }
    },
    click_text(content) {
      if (this.exists_text(content)) {
        var ui_text = text(content).findOne(MAX_SEARCH_TIME);
        var bounds = ui_text.bounds();
        this.click_bounds(bounds);
        return ui_text;
      } else {
        return false;
      }
    },
    exists_text_starts_with(content) {
      if (textStartsWith(content).exists()) {
        return textStartsWith(content).findOne(MAX_SEARCH_TIME);
      } else {
        return false;
      }
    },
    click_text_starts_with(content) {
      if (this.exists_text_starts_with(content)) {
        var ui_text = textStartsWith(content).findOne(MAX_SEARCH_TIME);
        var bounds = ui_text.bounds();
        this.click_bounds(bounds);
        return ui_text;
      } else {
        return false;
      }
    },
    exists_text_ends_with(content) {
      if (textEndsWith(content).exists()) {
        return textEndsWith(content).findOne(MAX_SEARCH_TIME);
      } else {
        return false;
      }
    },
    click_text_ends_with(content) {
      if (this.exists_text_ends_with(content)) {
        var ui_text = textEndsWith(content).findOne(MAX_SEARCH_TIME);
        var bounds = ui_text.bounds();
        this.click_bounds(bounds);
        return ui_text;
      } else {
        return false;
      }
    },
    exists_text_matches(content) {
      if (textMatches(content).exists()) {
        return textMatches(content).findOne(MAX_SEARCH_TIME);
      } else {
        return false;
      }
    },
    click_text_matches(content) {
      if (this.exists_text_matches(content)) {
        var ui_text = textMatches(content).findOne(MAX_SEARCH_TIME);
        var bounds = ui_text.bounds();
        this.click_bounds(bounds);
        return ui_text;
      } else {
        return false;
      }
    },
    get_center_point(x1, y1, x2, y2) {
      return {
        x: parseInt(x1 + (x2 - x1) / 2),
        y: parseInt(y1 + (y2 - y1) / 2),
      };
    },
    click_point(x1, y1, x2, y2) {
      var point = this.get_center_point(x1, y1, x2, y2);
      return this.click_x_y(point.x, point.y);
    },
    click_x_y(x, y) {
      return click(x, y);
    },
    get_number(content) {
      var reg_exp = /(\d+)/g;
      var number_match = content.match(reg_exp);
      var number = parseInt(number_match ? number_match[0] : 0);
      return number;
    },
    get_size_point(points, w, h) {
      var length = points.length;
      var size_points = [];
      var rate_x = device.width / (w || 720);
      var rate_y = device.height / (h || 1650);
      for (var i = 0; i < length; i++) {
        var point = points[i];
        var rate = i % 2 == 0 ? rate_x : rate_y;
        size_points.push(parseInt(point * rate));
      }
      return size_points;
    },
    get_random_interval(base, start, end, times) {
      start = start || 0;
      end = end || 0;
      times = times || 1000;
      return (base + random(start, end)) * times;
    },
    get_swipe_times(start, end) {
      start = start || 95;
      end = end || 5;
      return (start + random(0, end)) / 100;
    },
    create_logger() {
      var params = [];
      var length = arguments.length;
      for (var i = 0; i < length; i++) {
        params.push(arguments[i]);
      }
      return function () {
        var params_log = [];
        var length = arguments.length;
        for (var i = 0; i < length; i++) {
          params_log.push(arguments[i]);
        }
        console.log.apply(console.log, params.concat(params_log));
      };
    },
    random_index_array(max) {
      var result = [];
      while (result.length < max) {
        var number = random(0, max - 1);
        if (result.indexOf(number) == -1) {
          result.push(number);
        }
      }
      return result;
    },
    swipe(a, b, c, d) {
      swipe(
        device.width * a * this.get_swipe_times(95, 5),
        device.height * b * this.get_swipe_times(95, 5),
        device.width * c * this.get_swipe_times(95, 5),
        device.height * d * this.get_swipe_times(95, 5),
        utils$7.get_random_interval(200, 0, 800, 1)
      );
    },
    str_format(str, str2) {
      if (!str) {
        return "";
      }
      str2 = str2 || "哈";
      return str.split("").join(str2);
    },
    swipe_x(qx, qy, zx, zy, time) {
      sml_move(qx, qy, zx, zy, time);
    },
  };

  var utils_1 = utils$7;

  var utils$6 = utils_1;
  var app_utils_point_map = {
    最近任务的关闭: [269, 1410, 451, 1592],
  };
  var app_utils$1 = {
    openApp(app_name) {
      var logger = utils$6.create_logger("app_utils openApp: ");
      logger("");
      var result = app.launchApp(app_name);
      if (!result) {
        logger("打开应用--" + app_name + "--失败，可能没有安装该应用");
        return false;
      }
      logger("打开--" + app_name + "--成功");
      sleep(2 * 1000);
      return true;
    },
    open(package_name) {
      var logger = utils$6.create_logger("app_utils open: ");
      logger("");
      var result = app.launch(package_name);
      if (!result) {
        logger("打开应用--" + package_name + "--失败，可能没有安装该应用");
        return false;
      }
      logger("打开--" + package_name + "--成功");
      sleep(2 * 1000);
      return true;
    },
    close() {
      home();
      sleep(2 * 1000);
      recents();
      sleep(2 * 1000);
      utils$6.click_point.apply(
        utils$6,
        utils$6.get_size_point(app_utils_point_map["最近任务的关闭"])
      );
      return true;
    },
  };
  var app_utils_1 = app_utils$1;

  var time_utils_dateRegex = /(?=(YYYY|YY|MM|DD|HH|mm|ss|ms))\1([:\/]*)/g;
  var time_utils_timespan = {
    YYYY: ["getFullYear", 4],
    YY: ["getFullYear", 2],
    MM: ["getMonth", 2, 1], // getMonth is zero-based, thus the extra increment field
    DD: ["getDate", 2],
    HH: ["getHours", 2],
    mm: ["getMinutes", 2],
    ss: ["getSeconds", 2],
    ms: ["getMilliseconds", 3],
  };
  var time_utils$1 = {};

  time_utils$1.str = function (str, date, utc) {
    if (typeof str !== "string") {
      date = str;
      str = "YYYY-MM-DD";
    }

    if (!date) date = new Date();
    return str.replace(time_utils_dateRegex, function (match, key, rest) {
      var args = time_utils_timespan[key];
      var name = args[0];
      var chars = args[1];
      if (utc === true) name = "getUTC" + name.slice(3);
      var val = "00" + String(date[name]() + (args[2] || 0));
      return val.slice(-chars) + (rest || "");
    });
  };

  time_utils$1.utc = function (str, date) {
    return time_utils$1(str, date, true);
  };

  var time_utils_1 = time_utils$1;

  var time_utils = time_utils_1;
  var files_logger$2 = {
    get_file_name() {
      return time_utils.str("YYYY-MM-DD") + "/" + time_utils.str("HH-mm-ss");
    },
    write(app_name, action_name, text, file_name) {
      file_name = file_name || this.get_file_name();
      var path =
        "/sdcard/aaaaaaautojs-logger/" +
        app_name +
        "/" +
        action_name +
        "/" +
        file_name +
        ".txt";
      files.createWithDirs(path);
      files.write(path, text);
    },
    append(logger_name, action_name, text, file_name) {
      file_name = file_name || this.get_file_name();
      var path =
        "/sdcard/aaaaaaautojs-logger/" +
        logger_name +
        "/" +
        (action_name ? action_name + "/" : "") +
        file_name +
        ".txt";
      files.createWithDirs(path);
      files.append(path, text);
    },
    app_start_logger(app_name, content) {
      var logger_name = "app_start_logger";
      var action_name = null;
      var text =
        content ||
        time_utils.str("YYYY-MM-DD HH:mm:ss") + "  " + app_name + " 启动\n";
      var file_name = time_utils.str("YYYY-MM-DD");
      console.log("files_logger app_start_logger: ", text);
      this.append(logger_name, action_name, text, file_name);
    },
  };
  var files_logger_1 = files_logger$2;

  var utils$5 = utils_1;
  var files_logger$1 = files_logger_1;

  if (!requestScreenCapture()) {
    toastLog("请求截图权限失败");
    exit();
  }
  var OCR_UTIL_CONST_CHAR_MATCH_MAP = {
    搜: ["嫂", "樓", "接", "楼"],
    赚: ["廉", "嫌", "賺", "兼"],
    看: ["着", "春"],
    文: ["女"],
    章: ["拿"],
    钱: ["线"],
    觉: ["党"],
    户: ["戶"],
    索: ["素"],
    开: ["升", "研"],
    金: ["全"],
    积: ["枳"],
    币: ["市"],
    现: ["現"],
    领: ["領", "颌"],
    读: ["渎"],
    额: ["額"],
    取: ["驭"],
    视: ["规", "初"],
    享: ["亨"],
    兑: ["兌"],
    提: ["堤"],
    体: ["休"],
    才: ["オ"],
    街: ["衔"],
    城: ["械"],
    间: ["闻"],
    来: ["來"],
    十: ["+"],
  };

  var ocr_utils$3 = {
    get_reg_exp(content) {
      var reg_exp_string = content
        .split("")
        .map(function (item) {
          var match = OCR_UTIL_CONST_CHAR_MATCH_MAP[item];
          var piece = match
            ? "[" + match.concat(item).join("") + "]+"
            : "[" + item + "]+";
          return piece + `\\s*`;
        })
        .join("");
      var reg_exp = new RegExp(reg_exp_string, "gi");
      return {
        text: content,
        reg_exp: reg_exp,
      };
    },
    toArray(array_like) {
      var array = [];
      for (var i = 0; i < array_like.length; i++) {
        array.push(array_like[i]);
      }
      return array;
    },
    screen_exists_text_all(content, log_ocr_texts) {
      var logger = utils$5.create_logger("ocr_util screen_exists_text_all: ");
      logger("");
      if (!Array.isArray(content)) {
        content = [content];
      }
      var content_configs = content.map((item) => {
        return {
          text: content,
          reg_exp: this.get_reg_exp(item).reg_exp,
          find: null,
        };
      });
      if (log_ocr_texts) {
        logger(
          "正则表达式是--" +
            content_configs.map((item) => item.reg_exp.toString()).join(" || ") +
            "--"
        );
      }
      var startTime = Date.now();
      var capture_img = captureScreen();
      if (!capture_img) {
        toastLog("截图失败");
      }
      var endTime = Date.now();
      logger("截图耗费-" + (endTime - startTime) / 1000 + "-s");
      var capture_img_orc_results = this.toArray(
        gmlkit.ocr(capture_img, "zh").toArray(3)
      );
      capture_img.recycle();
      for (var i = 0; i < capture_img_orc_results.length; i++) {
        var item = capture_img_orc_results[i];
        for (var j = 0; j < content_configs.length; j++) {
          var content_config = content_configs[j];
          if (!content_config.find && content_config.reg_exp.test(item.text)) {
            content_config.find = item;
            break;
          }
        }
        if (content_configs.every((item) => item.find)) {
          break;
        }
      }

      if (content_configs.some((item) => !item.find)) {
        if (log_ocr_texts) {
          var no_finds = content_configs
            .filter((item) => !item.find)
            .map((item) => item.text)
            .join(" || ");
          logger("没找到--" + no_finds + "--");
          var file_name = files_logger$1.get_file_name();
          logger("已经记录到--ocr_error--,文件名字为--" + file_name + "--");
          files_logger$1.write(
            "ocr_result",
            "error",
            "要找的是：" +
              no_finds +
              "\n" +
              "但是没找到，下面是ocr识别的结果：" +
              "\n" +
              capture_img_orc_results.map((item) => item.text).join("\n"),
            file_name
          );
        }
        return false;
      }
      return true;
    },
    screen_exists_text_one(content, log_ocr_texts) {
      var logger = utils$5.create_logger("ocr_util screen_exists_text_one: ");
      if (!Array.isArray(content)) {
        content = [content];
      }
      var content_configs = content.map((item) => {
        return {
          text: content,
          reg_exp: this.get_reg_exp(item).reg_exp,
          find: null,
        };
      });
      if (log_ocr_texts) {
        logger(
          "正则表达式是--" +
            content_configs.map((item) => item.reg_exp.toString()).join(" || ") +
            "--"
        );
      }
      var startTime = Date.now();
      var capture_img = captureScreen();
      if (!capture_img) {
        toastLog("截图失败");
      }
      var endTime = Date.now();
      logger("截图耗费-" + (endTime - startTime) / 1000 + "-s");
      var capture_img_orc_results = this.toArray(
        gmlkit.ocr(capture_img, "zh").toArray(3)
      );
      capture_img.recycle();
      for (var i = 0; i < capture_img_orc_results.length; i++) {
        var item = capture_img_orc_results[i];
        for (var j = 0; j < content_configs.length; j++) {
          var content_config = content_configs[j];
          if (content_config.reg_exp.test(item.text)) {
            content_config.find = item;
            return item;
          }
        }
      }

      if (content_configs.every((item) => !item.find)) {
        if (log_ocr_texts) {
          var no_finds = content_configs.map((item) => item.text).join(" && ");
          logger("没找到--" + no_finds + "--");
          var file_name = files_logger$1.get_file_name();
          logger("已经记录到--ocr_error--,文件名字为--" + file_name + "--");
          files_logger$1.write(
            "ocr_result",
            "error",
            "要找的是：" +
              no_finds +
              "\n" +
              "但是没找到，下面是ocr识别的结果：" +
              "\n" +
              capture_img_orc_results.map((item) => item.text).join("\n"),
            file_name
          );
        }
        return false;
      }
      return true;
    },
    capture_then_log_text() {
      var logger = utils$5.create_logger("capture_then_log_text: ");
      var startTime = Date.now();
      var capture_img = captureScreen();
      if (!capture_img) {
        toastLog("截图失败");
      }
      var endTime = Date.now();
      logger("截图耗费-" + (endTime - startTime) / 1000 + "-s");
      var capture_img_orc_results = this.toArray(
        gmlkit.ocr(capture_img, "zh").toArray(3)
      );
      capture_img.recycle();
      console.log(capture_img_orc_results.map((item) => item.text).join("\n"));
    },
    capture_exists_text(content, log_ocr_texts) {
      if (!Array.isArray(content)) {
        content = [content];
      }
      var configs = content.map((item) => {
        return this.get_reg_exp(item);
      });
      if (log_ocr_texts) {
        console.log(
          "ocr_utils capture_exists_text: " +
            "正则表达式是：--" +
            configs.map((item) => item.reg_exp).join(" || ") +
            "--"
        );
      }
      return this.capture_exists_match(configs, log_ocr_texts);
    },
    capture_exists_match(reg_exp_configs, log_ocr_texts) {
      var startTime = Date.now();
      var capture_img = captureScreen();
      if (!capture_img) {
        toastLog("截图失败");
      }
      var endTime = Date.now();
      logger("截图耗费-" + (endTime - startTime) / 1000 + "-s");
      var capture_img_orc_results = this.toArray(
        gmlkit.ocr(capture_img, "zh").toArray(3)
      );
      capture_img.recycle();
      for (var i = 0; i < capture_img_orc_results.length; i++) {
        var item = capture_img_orc_results[i];
        if (
          reg_exp_configs.some((reg_exp_config) => {
            return reg_exp_config.reg_exp.test(item.text);
          })
        ) {
          console.log("找到--" + item.text + "--");
          return item;
        }
      }
      console.log(
        "ocr_util capture_exists_match: 没找到: " +
          reg_exp_configs.map((item) => item.text).join(" || ")
      );
      if (log_ocr_texts) {
        var file_name = files_logger$1.get_file_name();
        console.log("已经记录到--ocr_error--,文件名字为--" + file_name + "--");
        files_logger$1.write(
          "ocr_result",
          "error",
          "要找的是：" +
            reg_exp_configs.map((item) => item.text).join(" || ") +
            "\n" +
            "但是没找到，下面是ocr识别的结果：" +
            "\n" +
            capture_img_orc_results.map((item) => item.text).join("\n"),
          file_name
        );
      }
    },
    find_text(
      content,
      log_ocr_texts,
      if_is_end,
      max_swipe_times,
      swipe_instance
    ) {
      if (!Array.isArray(content)) {
        content = [content];
      }
      max_swipe_times = max_swipe_times || 10;
      log_ocr_texts = log_ocr_texts || false;
      swipe_instance = swipe_instance || 200;
      var reg_exp_configs = content.map((item) => {
        return this.get_reg_exp(item);
      });
      while (max_swipe_times > 0) {
        var result = this.capture_exists_match(reg_exp_configs, log_ocr_texts);
        if (result) {
          return result;
        }
        swipe(
          (device.width / 2) * utils$5.get_swipe_times(98, 2),
          (device.height / 2) * utils$5.get_swipe_times(98, 2),
          (device.width / 2) * utils$5.get_swipe_times(98, 2),
          (device.height / 2 - swipe_instance) * utils$5.get_swipe_times(98, 2),
          utils$5.get_random_interval(2, 0, 3, 100)
        );
        sleep(2 * 1000);
        max_swipe_times -= 1;
        if (if_is_end && if_is_end()) {
          break;
        }
      }
    },
    find_text_all(
      content,
      log_ocr_texts,
      if_is_end,
      max_swipe_times,
      swipe_instance
    ) {
      var logger = utils$5.create_logger("ocr_util find_text_all: ");
      if (!Array.isArray(content)) {
        content = [content];
      }
      var content_configs = content.map((item) => {
        return {
          text: item,
          reg_exp: this.get_reg_exp(item).reg_exp,
          result: null,
        };
      });
      if (log_ocr_texts) {
        logger(
          "正则表达式是： --" +
            content_configs.map((item) => item.reg_exp).join(" || ") +
            "--"
        );
      }
      max_swipe_times = max_swipe_times || 10;
      log_ocr_texts = log_ocr_texts || false;
      swipe_instance = swipe_instance || (device.height / 10) * 1;
      var ocr_text_results = [];
      while (max_swipe_times > 0) {
        var startTime = Date.now();
        var capture_img = captureScreen();
        if (!capture_img) {
          toastLog("截图失败");
        }
        var endTime = Date.now();
        logger("截图耗费-" + (endTime - startTime) / 1000 + "-s");
        var capture_orc_results = this.toArray(
          gmlkit.ocr(capture_img, "zh").toArray(3)
        );
        capture_img.recycle();
        for (var i = 0; i < capture_orc_results.length; i++) {
          var item = capture_orc_results[i];
          for (var j = 0; j < content_configs.length; j++) {
            var content_config = content_configs[j];
            var text = content_config.text;
            var reg_exp = content_config.reg_exp;
            if (reg_exp.test(item.text)) {
              ocr_text_results.push({
                text,
                reg_exp,
                result: item,
              });
              logger("找到--" + item.text + "--");
              break;
            }
          }
          if (ocr_text_results.length == content_configs.length) {
            break;
          }
        }
        if (ocr_text_results.length > 0) {
          return ocr_text_results;
        }
        if (ocr_text_results.length == 0) {
          if (log_ocr_texts) {
            var file_name = files_logger$1.get_file_name();
            logger(
              "当前页面没有找到--" +
                content_configs.map((item) => item.text).join(" || ") +
                "--,已经记录在--ocr_error--,文件名字为--" +
                file_name +
                "--"
            );
            files_logger$1.write(
              "ocr_result",
              "error",
              "要找的是：" +
                content_configs.map((item) => item.text).join(" || ") +
                "\n" +
                "但是没找到，下面是ocr识别的结果：" +
                "\n" +
                capture_orc_results.map((item) => item.text).join("\n"),
              file_name
            );
          } else {
            logger(
              "当前页面没有找到--" +
                content_configs.map((item) => item.text).join(" || ")
            );
          }
        }
        swipe(
          (device.width / 2) * utils$5.get_swipe_times(98, 2),
          (device.height / 2) * utils$5.get_swipe_times(98, 2),
          (device.width / 2) * utils$5.get_swipe_times(98, 2),
          (device.height / 2) * utils$5.get_swipe_times(98, 2) - swipe_instance,
          utils$5.get_random_interval(2, 0, 3, 100)
        );
        sleep(2 * 1000);
        max_swipe_times -= 1;
        if (if_is_end && if_is_end()) {
          return ocr_text_results;
        }
      }
      return ocr_text_results;
    },
  };

  var ocr_utils_1 = ocr_utils$3;

  var utils$4 = utils_1;

  var AD_CONST_MIN_INTERVAL = 40;
  var AD_CONST_MAX_GO_BACK_TIMES = 4;

  var ad$1 = {
    in_task: false,
    in_home: false,
    if_current_ad_is_over: null, //判断广告实际是否比预计时间提前结束
    if_in_home: null, //判断是否在首页
    if_in_task: null, //判断是否是在任务页
    has_next_contents: [], //判断是否有下一个广告
    has_watch_ad_times: 0,
    max_ad_times: 1000,
    init(
      if_current_ad_is_over,
      if_in_task,
      if_in_home,
      has_next_contents,
      max_ad_times
    ) {
      console.show();
      var logger = utils$4.create_logger("ad init: ");
      logger("");
      this.if_current_ad_is_over = //判断当前广告是否已经结束
        if_current_ad_is_over ||
        function () {
          var over_contents = ["已领取", "已完成任务"];
          for (var i = 0; i < over_contents.length; i++) {
            var over_content = over_contents[i];
            if (utils$4.exists_text_starts_with(over_content)) {
              logger("找到-" + utils$4.str_format(over_content) + "-");
              return true;
            }
          }
          return false;
        };
      this.if_in_task = //判断是否在开始看广告的页面
        if_in_task ||
        function () {
          var in_task_contents = ["立即收下", "开心收下", "现金收益"];
          for (var i = 0; i < in_task_contents.length; i++) {
            var in_task_content = in_task_contents[i];
            if (utils$4.exists_text_starts_with(in_task_content)) {
              console.log(
                "ad init: 找到-" + utils$4.str_format(in_task_content) + "-"
              );
              return true;
            }
          }
          return false;
        };
      this.if_in_home = //判断是否在app首页
        if_in_home ||
        function () {
          return (
            utils$4.exists_text_starts_with("百度") &&
            utils$4.exists_text_starts_with("听书")
          );
        };
      this.has_next_contents = has_next_contents || [
        //判断是否有下一个广告可以观看
        "再看一个领取",
        "再看一条领取",
        "再看1个获得",
        "换个视频",
      ];
      this.max_ad_times = utils$4.get_random_interval(
        max_ad_times || 1000,
        0,
        1,
        1
      );
      logger("本轮最多看-" + this.max_ad_times + "-个广告");
      //开始看广告
      var ad_interval = AD_CONST_MIN_INTERVAL + random(0, 5);
      logger("即将开始看广告，预计时间" + ad_interval + "s");
      this.run(ad_interval);
    },
    run(ad_interval) {
      var logger = utils$4.create_logger("ad run: ");
      logger("下面开始看第-" + (this.has_watch_ad_times + 1) + "-个广告");
      logger("本次广告时长预计-" + ad_interval + "-秒");
      var if_current_ad_is_over_interval = 2; //每隔2s检查当前广告是否已经结束
      var is_over_early = false;
      var count = 0;
      while (ad_interval > if_current_ad_is_over_interval) {
        if (this.if_current_ad_is_over && this.if_current_ad_is_over()) {
          var last_wait_interval = random(1, 2);
          logger("广告已结束,再等待" + last_wait_interval + "s后停止当前广告");
          sleep(last_wait_interval * 1000);
          is_over_early = true; //广告实际比预计的时间提前结束
          break;
        }
        sleep(if_current_ad_is_over_interval * 1000);
        ad_interval = ad_interval - if_current_ad_is_over_interval;
        count = count + 1;
        if (count % 5 == 0) {
          logger("广告时间预计还剩" + ad_interval + "秒");
        }
      }
      if (is_over_early) {
        this.has_watch_ad_times = this.has_watch_ad_times + 1;
        this.go_back();
        return;
      }
      if (ad_interval > 0) {
        logger("广告时间还剩最后的" + ad_interval + "秒");
        sleep(ad_interval * 1000);
        this.has_watch_ad_times = this.has_watch_ad_times + 1;
        this.go_back();
        return;
      }
    },
    go_back() {
      var logger = utils$4.create_logger("ad go_back: ");
      var index = 0;
      while (index < AD_CONST_MAX_GO_BACK_TIMES) {
        back();
        sleep(utils$4.get_random_interval(1200, 0, 1000, 1));
        for (var i = 0; i < this.has_next_contents.length; i++) {
          var content = this.has_next_contents[i];
          if (utils$4.exists_text_starts_with(content)) {
            logger("找到-" + utils$4.str_format(content) + "-");
            if (this.has_watch_ad_times >= this.max_ad_times) {
              var leave_contents = ["残忍离开"];
              for (var i = 0; i < leave_contents.length; i++) {
                var leave_content = leave_contents[i];
                if (utils$4.click_text_starts_with(leave_content)) {
                  logger(
                    "本轮看广告次数大于-" +
                      this.max_ad_times +
                      "-，找到-" +
                      utils$4.str_format(leave_content) +
                      "-,将结束本轮看广告"
                  );
                  sleep(utils$4.get_random_interval(1200, 0, 1000, 1));
                  this.in_task = true;
                  this.after();
                  return;
                }
              }
            }

            utils$4.click_text_starts_with(content);
            sleep(2 * 1000);
            //开始看下一次的广告
            var ad_interval = AD_CONST_MIN_INTERVAL + random(0, 5);
            logger("即将开始看广告，预计时间" + ad_interval + "s");
            this.run(ad_interval);
            return;
          }
        }
        if (this.if_in_task && this.if_in_task()) {
          logger("判断在任务页");
          this.in_task = true;
          this.after();
          return;
        }
        if (this.if_in_home && this.if_in_home()) {
          logger("判断在app首页");
          this.in_home = true;
          this.after();
          return;
        }
        console.log("ad go_back: 第" + (index + 1) + "次执行back");
        index = index + 1;
      }
      this.after();
    },
    after() {
      console.log("ad after");
      this.next();
    },
    next() {
      console.log("ad next");
      console.hide();
    },
  };
  var ad_1 = ad$1;

  var utils$3 = utils_1;
  var ocr_utils$2 = ocr_utils_1;
  var ad = ad_1;
  var in_task$1 = {
    init(
      end_contents,
      ad_contents,
      has_next_contents,
      if_current_ad_is_over,
      if_in_task,
      if_in_home,
      max_ad_times
    ) {
      var logger = utils$3.create_logger("in_task init: ");
      var end_contents = end_contents || ["开心收下", "立即收下"];
      for (var i = 0; i < end_contents.length; i++) {
        var end_content = end_contents[i];
        if (utils$3.click_text_starts_with(end_content)) {
          logger("找到--" + utils$3.str_format(end_content) + "--");
          sleep(2 * 1000);
          this.next();
          return;
        }
      }

      var end_contents = end_contents || ["开心收下", "立即收下"];
      for (var i = 0; i < end_contents.length; i++) {
        var end_content = end_contents[i];
        var ocr_text = ocr_utils$2.screen_exists_text_one(end_content, false);
        if (ocr_text) {
          utils$3.click_ocr_text(ocr_text);
          logger("找到 ocr_text --" + utils$3.str_format(end_content) + "--");
          sleep(2 * 1000);
          this.next();
          return;
        }
      }
      var ad_contents = ad_contents || ["看广告再", "观看视频再得", "看视频再领"];
      for (var i = 0; i < ad_contents.length; i++) {
        var ad_content = ad_contents[i];
        if (utils$3.click_text_starts_with(ad_content)) {
          logger("找到--" + utils$3.str_format(ad_content) + "--");
          sleep(2 * 1000);
          ad.has_watch_ad_times = 0;
          ad.max_ad_times = 1000;
          ad.init(
            if_current_ad_is_over,
            if_in_task,
            if_in_home,
            has_next_contents,
            max_ad_times
          );
          if (ad.in_task) {
            this.init();
            return;
          }
          this.after();
          return;
        }
      }
      this.after();
    },
    after() {
      console.log("in_task after");
      this.next();
    },
    next() {
      console.log("in_task next");
    },
  };
  var inTask = in_task$1;

  var point_map$1 = {
    首页百度: [0, 1502, 146, 1618],
    首页福利: [440, 1502, 574, 1618],
  };
  var pointMap = point_map$1;

  var utils$2 = utils_1;
  var ocr_utils$1 = ocr_utils_1;
  var READ_CONST_EVERY_ARTICLE_SWIPE_TIMES = 10;
  var read$1 = {
    go_page_from_home() {
      var logger = utils$2.create_logger("read go_page_from_home: ");
      if (ocr_utils$1.screen_exists_text_all(["百度", "听书"], true)) {
        logger("");
        if (utils$2.click_text_starts_with("百度")) {
          logger("找到-" + utils$2.str_format("百度") + "-");
          sleep(utils$2.get_random_interval(2, 0, 1, 1000));
        } else {
          logger("没找到-" + utils$2.str_format("百度") + "-");
        }
        // if (utils.click_text_starts_with("热搜")) {
        //   logger("找到--热搜--");
        //   sleep(utils.get_random_interval(2, 0, 1, 1000));
        // } else {
        //   logger("没找到--热搜--");
        // }
        this.init();
      } else {
        logger("NOT FOUND");
        this.after();
      }
    },
    init() {
      var logger = utils$2.create_logger("read init: ");
      var content = ["听文章"];
      var ocr_text_results = ocr_utils$1.find_text_all(content, false);
      var length = ocr_text_results.length;
      if (length > 0) {
        logger("找到--" + length + "个--" + content.join("|||") + "--");
        var times = READ_CONST_EVERY_ARTICLE_SWIPE_TIMES;
        for (var i = 0; i < length; i++) {
          if (i == 1) {
            break;
          }
          var { result } = ocr_text_results[i];
          this.run(i, result, times);
        }
        this.after();
      } else {
        logger("没找到--" + content.join(" 或 ") + "--");
        this.after();
      }
    },
    check_is_over() {
      var logger = utils$2.create_logger("read check_is_over: ");
      var is_over_contents = ["立即评论", "没有更多", "抢沙发"];
      var ocr_text = ocr_utils$1.screen_exists_text_one(is_over_contents);
      if (ocr_text) {
        logger("找到-" + is_over_contents.join(" 或 ") + "-");
      }
      return ocr_text;
    },
    run(i, result, times) {
      var logger = utils$2.create_logger("read run: ");
      logger(
        "开始阅读第--" + (i + 1) + "--篇文章,找到的是--" + result.text + "--"
      );
      utils$2.click_x_y(device.width / 2, result.bounds.centerY());
      sleep(utils$2.get_random_interval(2, 0, 1, 1000));
      var swipe_times = times + random(0, 5);
      logger("将滑动--" + swipe_times + "--次");
      while (swipe_times > 0) {
        swipe(
          (device.width / 2) * utils$2.get_swipe_times(95, 5),
          (device.height / 10) * 8 * utils$2.get_swipe_times(95, 5),
          (device.width / 2) * utils$2.get_swipe_times(95, 5),
          (device.height / 10) * 1 * utils$2.get_swipe_times(95, 5),
          utils$2.get_random_interval(2, 0, 3, 100)
        );
        sleep(utils$2.get_random_interval(1, 0, 1, 1000));
        var is_over = this.check_is_over();
        if (is_over) {
          logger("判断阅读已经结束，将结束阅读");
          break;
        }
        sleep(utils$2.get_random_interval(1, 0, 1, 1000));
        swipe_times = swipe_times - 1;
      }
      back();
      sleep(utils$2.get_random_interval(2, 0, 1, 1000));
    },
    after() {
      console.log("read after");
      this.next();
    },
    next() {
      console.log("read next");
    },
  };
  var taskRead = read$1;

  var utils$1 = utils_1;
  var ocr_utils = ocr_utils_1;
  var in_task = inTask;
  var point_map = pointMap;
  var treasure$1 = {
    go_page_from_home() {
      var logger = utils$1.create_logger("treasure go_page_from_home: ");
      logger();
      if (ocr_utils.screen_exists_text_all(["百度", "听书"], true)) {
        logger("SUCCESS");
        utils$1.click_point.apply(
          utils$1,
          utils$1.get_size_point(point_map["首页福利"])
        );
        var interval = utils$1.get_random_interval(6, 0, 2, 1000);
        logger("等待-" + interval / 1000 + "-秒后开始开宝箱");
        sleep(interval);
        this.init();
      } else {
        logger("NOT FOUND");
      }
    },
    is_over_today: false,
    init() {
      var logger = utils$1.create_logger("treasure init: ");
      if (this.is_over_today) {
        logger("今天的开宝箱任务已经全部完毕");
        return;
      }
      in_task.init(null, null, null, null, null, null, 3);
      var ui_text = utils$1.click_text("开宝箱得金币");
      if (ui_text) {
        logger("treasure init: 找到" + utils$1.str_format("开宝箱得金币"));
        sleep(2 * 1000);
        this.run();
        return;
      }
      logger("没找到" + utils$1.str_format("开宝箱得金币"));
      if (utils$1.exists_text_starts_with("明天再来")) {
        this.is_over_today = true;
        logger(
          "找到-" +
            utils$1.str_format("明天再来") +
            "-,今天的开宝箱任务已经全部完毕"
        );
      }
      this.next();
    },
    run() {
      in_task.init(null, null, null, null, null, null, 3);
      this.next();
    },
    next() {
      console.log("treasure next");
    },
  };
  var taskTreasure = treasure$1;

  var utils = utils_1;
  var app_utils = app_utils_1;
  var files_logger = files_logger_1;
  var read = taskRead;
  var treasure = taskTreasure;
  var APP_CONST_NAME = "百度大字版";
  var APP_CONST_NAME_two = "百度畅听版";
  var main = {
    exec_times: 0,
    is_over: false,
    last_run_time: null,
    run() {
      if (this.last_run_time) {
        var interval = Date.now() - this.last_run_time;
        if (interval < 5 * 60 * 1000) {
          console.show();
          console.log(
            "打开--百度大字版--间隔小于5分钟，将等待30s,并跳过本次任务"
          );
          sleep(30 * 1000);
          console.hide();
          sleep(2 * 1000);
          return;
        }
      }
      var result =
        app_utils.openApp(APP_CONST_NAME) ||
        app_utils.openApp(APP_CONST_NAME_two);
      if (!result) {
        console.log("没有安装--百度大字版--，跳过本次任务");
        return;
      } else {
        files_logger.app_start_logger("百度大字版");
      }

      this.last_run_time = Date.now();
      this.exec_times = this.exec_times + 1;

      sleep(utils.get_random_interval(6, 0, 2, 1000));

      var tasks = [read, treasure];
      var task_index_array = utils.random_index_array(2);
      console.log("baidudazi task_index_array: ", task_index_array);

      for (var i = 0; i < task_index_array.length; i++) {
        var task = tasks[task_index_array[i]];
        task.go_page_from_home();
        sleep(utils.get_random_interval(2, 0, 2, 1000));
      }

      app_utils.close();
      console.log("百度大字版 main: 执行完成本轮任务");
      var content =
        "百度大字版,本次运行耗时：" +
        ((Date.now() - this.last_run_time) / 1000).toFixed(2) +
        "s,大约" +
        ((Date.now() - this.last_run_time) / 1000 / 60).toFixed(2) +
        "分钟。今天已经运行-" +
        this.exec_times +
        "-次!\n";
      files_logger.app_start_logger("百度大字版", content);
      sleep(utils.get_random_interval(2, 0, 1, 1000));
    },
  };
  main.run();

  return test;

})();
